import { category } from '@/api/index'
const state = {
    category1List: [],//一级分类列表
    category2List: [],// 二级分类列表
    category3List: [],// 三级分类列表
}
const mutations = {
    // 存储一级分类列表
    CHANGE_CATEGORY1(state, category1List) {
        // console.log(category1List)
        state.category1List = category1List
    },
    //    存储二级分类列表
    CHANGE_CATEGORY2(state, category2List){
        state.category2List = category2List
    },
        //  存储三级分类列表
    CHANGE_CATEGORY3(state,category3List){
        state.category3List = category3List
    }
}
const actions = {
    // 获取一级分类列表
    async getCategory1List({ commit }) {
        let result = await category.getCategory1()
        commit('CHANGE_CATEGORY1', result.data)
    },
    // 获取二级分类列表
    async getCategory2List({ commit }, id) {
        let result = await category.getCategory2(id)
        // console.log(result);
        commit('CHANGE_CATEGORY2', result.data,id)
    },
    // 获取三级分类列表
     async getCategory3List({ commit }, id) {
        let result = await category.getCategory3(id)
        // console.log(result);
        commit('CHANGE_CATEGORY3', result.data)
    }
}
const getters = {}
export default {
    state, mutations, actions, getters
}
